package com.wang.madness.customResponse;

import com.wang.madness.customEnum.ResultCode;
import lombok.Data;

/**
 * 返回成功的请求
 * @author DanielWu
 */
@Data
public class SuccessResult<T> {

  private int code;

  private String status;

  private String loginType;

  private String msg;

  private T data;

  public SuccessResult () {
    this.status = "ok";
    this.loginType = "account";
    this.code = ResultCode.SUCCESS.getCode();
    this.msg = ResultCode.SUCCESS.getMsg();
  }

  public SuccessResult (T data) {
    this("account", "ok", ResultCode.SUCCESS, data);
  }

  public SuccessResult (String loginType, ResultCode resultCode, T data) {
    this.loginType = loginType;
    this.status = "ok";
    this.code = resultCode.getCode();
    this.msg = resultCode.getMsg();
    this.data = data;
  }

  public SuccessResult (String loginType, String status, ResultCode resultCode) {
    this.loginType = loginType;
    this.status = status;
    this.code = resultCode.getCode();
    this.msg = resultCode.getMsg();
  }

  public SuccessResult (String loginType, String status, ResultCode resultCode, T data) {
    this.loginType = loginType;
    this.status = status;
    this.code = resultCode.getCode();
    this.msg = resultCode.getMsg();
    this.data = data;
  }

  public static<T> SuccessResult<T> ok(){
    return new SuccessResult<>();
  }

  public static<T> SuccessResult<T> ok(T data){
    return new SuccessResult<>(data);
  }

}
